<?php

class PracticeTestTemporaryResultModel extends CoreModel {

	function __construct()
	{
		parent::__construct();
	}

	public function returnTable()
	{
		return $this->PracticeTestTemporaryResults;
	}

	public function getCurrentDoing($id,$user)
	{
		return $this->wpdb->get_row("SELECT * FROM ".$this->returnTable()." WHERE practice_test_id=".$id." AND user_id='".$user."'");
	}

	public function getTimeResult($id,$user)
	{
		return $this->wpdb->get_row("SELECT time_start,time_stop,time_finish FROM ".$this->returnTable()." WHERE practice_test_id=".$id." AND user_id='".$user."'");
	}

	public function getPoints($id,$user)
	{
		return $this->wpdb->get_var("SELECT point FROM ".$this->returnTable()." WHERE practice_test_id=".$id." AND user_id='".$user."'");
	}

	public function getNumAnswer($id,$user)
	{
		return $this->wpdb->get_var("SELECT number_answer FROM ".$this->returnTable()." WHERE practice_test_id=".$id." AND user_id='".$user."'");
	}

		public function getTimerDoing($id,$user)
	{
		return $this->wpdb->get_var("SELECT time_stop FROM ".$this->returnTable()." WHERE practice_test_id=".$id." AND user_id='".$user."'");
	}

	public function getNextDoing($id,$user)
	{
		return $this->wpdb->get_var("SELECT next_date_answer FROM ".$this->returnTable()." WHERE practice_test_id=".$id." AND user_id='".$user."'");
	}

	public function getTimerStop($id,$user)
	{
		return $this->wpdb->get_var("SELECT time_stop FROM ".$this->returnTable()." WHERE practice_test_id=".$id." AND user_id='".$user."'");
	}

	public function getCurrentQuestion($id,$user)
	{
		$q = $this->wpdb->get_var("SELECT current_question FROM ".$this->returnTable()." WHERE practice_test_id=".$id." AND user_id='".$user."'");
		return !empty($q) ? $q : 0;
	}

	public function exists($id)
	{
		$q = $this->wpdb->get_var("SELECT id FROM ".$this->returnTable()." WHERE practice_test_id=".$id);
		return !empty($q) ? true : false;
	}


	public function isExists($id,$user)
	{
		$q = $this->wpdb->get_var("SELECT id FROM ".$this->returnTable()." WHERE practice_test_id=".$id." AND user_id='".$user."'");
		return !empty($q) ? true : false;
	}

	public function isSuccess($id,$user)
	{
		$q = $this->wpdb->get_var("SELECT id FROM ".$this->returnTable()." WHERE practice_test_id=".$id." AND is_success=1 AND user_id='".$user."'");
		return !empty($q) ? true : false;
	}

	public function userExists($user)
	{
		$q = $this->wpdb->get_var("SELECT id FROM ".$this->returnTable()." WHERE user_id='".$user."'");
		return !empty($q) ? true : false;
	}

	public function getResultOfUser($id,$user)
	{
		return $this->wpdb->get_row("SELECT is_true,is_false FROM ".$this->returnTable()." WHERE user_id='".$user."' AND practice_test_id=".$id);
	}

	public function getNumberAnswerCorrect($id,$user)
	{
		return $this->wpdb->get_var("SELECT number_correct FROM ".$this->returnTable()." WHERE user_id='".$user."' AND practice_test_id=".$id);
	}

	public function getNumberAnswerWrong($id,$user)
	{
		return $this->wpdb->get_var("SELECT number_wrong FROM ".$this->returnTable()." WHERE user_id='".$user."' AND practice_test_id=".$id);
	}

}